﻿using System.Collections.Generic;

namespace Utility.Persistence_Service_Test.Entities
{
    public class Besucher
    {
        public virtual int Id { get; protected set; }

        public virtual int Nummer { get; set; }

        public virtual string Vorname { get; set; }

        public virtual string Nachname { get; set; }

        public virtual Bankkonto Bankkonto { get; set; }

        public virtual IList<Kinokarte> Kinokarten { get; set; }

        public Besucher()
        {
            Kinokarten = new List<Kinokarte>();
        }

        public virtual void AddKinokarte(Kinokarte kinokarte)
        {
            kinokarte.Besucher = this;
            Kinokarten.Add(kinokarte);
        }

        public virtual void SetBankkonto(Bankkonto bankkonto)
        {
            this.Bankkonto = bankkonto;
            bankkonto.Besucher = this;
        }

        public override bool Equals(System.Object obj)
        {
            if (obj == null)
            {
                return false;
            }

            if (GetType() != obj.GetType())
            {
                return false;
            }

            Besucher besucher = (Besucher)obj;

            return (Id.Equals(besucher.Id)) && (Nummer.Equals(besucher.Nummer)) &&
                (Vorname.Equals(besucher.Vorname)) && (Nachname.Equals(besucher.Nachname)) &&
                (Bankkonto.Equals(besucher.Bankkonto));
        }

        public override int GetHashCode()
        {
            int prime = 31;
            int result = 1;
            result = prime * result + Id.GetHashCode();
            result = prime * result + Nummer.GetHashCode();
            result = prime * result + Vorname.GetHashCode();
            result = prime * result + Nachname.GetHashCode();
            result = prime * result + Bankkonto.GetHashCode();
            return result;
        }

        public override string ToString()
        {
            return "Besucher: {Id: " + this.Id.ToString() + ", Nummer: " + this.Nummer.ToString() + 
                ", Vorname: " + this.Vorname.ToString() + ", Nachname: " + this.Nachname.ToString() + 
                ", " + this.Bankkonto.ToString() + "}";
        }
    }
}
